import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';

import { error, success } from '@/utils';

import { AuthService } from './auth.service';
import { CreateAuthDto } from './dto/create-auth.dto';
import { UpdateAuthDto } from './dto/update-auth.dto';
import { Public } from './public.decorator';

@Controller('auth')
export class AuthController {
    constructor(private readonly authService: AuthService) {}

    @Post('login')
    @Public()
    async login(@Body() body: any) {
        return this.authService
            .login(body)
            .then((data) => success(data, '登录成功'))
            .catch((err) => error(err.message));
    }

    @Post()
    create(@Body() createAuthDto: CreateAuthDto) {
        return 'this.authService.create(createAuthDto)';
    }

    @Get()
    findAll() {
        return this.authService.findAll();
    }

    @Get(':id')
    findOne(@Param('id') id: string) {
        return this.authService.findOne(+id);
    }

    @Patch(':id')
    update(@Param('id') id: string, @Body() updateAuthDto: UpdateAuthDto) {
        return this.authService.update(+id, updateAuthDto);
    }

    @Delete(':id')
    remove(@Param('id') id: string) {
        return this.authService.remove(+id);
    }
}
